package com.kurumi.thread;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.kurumi.constant.HomepageConstatnt;
import com.kurumi.domain.ShandongHomepageExcelDTO;
import com.kurumi.pojo.homepage.MedicalRecordBasic;
import com.kurumi.pojo.homepage.MedicalRecordCost;
import com.kurumi.pojo.homepage.MedicalRecordDiagnoss;
import com.kurumi.pojo.homepage.MedicalRecordDoctor;
import com.kurumi.pojo.homepage.MedicalRecordIcu;
import com.kurumi.pojo.homepage.MedicalRecordNurse;
import com.kurumi.pojo.homepage.MedicalRecordOperation;
import com.kurumi.pojo.homepage.MedicalRecordTransfusion;
import com.kurumi.pojo.homepage.MedicalRecordTurn;
import com.kurumi.service.MedicalRecordDataManageService;
import com.kurumi.util.DateUtil;
import com.kurumi.util.ObjectUtils;

/**
 * 首页数据处理多线程
 * 
 * @author liyutao
 *
 */
public class HomePageSaveCallable implements Callable<Integer> {

	private static final Logger logger = LoggerFactory.getLogger(HomePageSaveCallable.class);

	/**
	 * 分批guid集合
	 */
	private List<String> guidList;

	private MedicalRecordDataManageService medicalRecordDataManageService;

	public HomePageSaveCallable() {

	}

	public HomePageSaveCallable(List<String> guidList,
			MedicalRecordDataManageService medicalRecordDataManageService) {
		this.guidList = guidList;
		this.medicalRecordDataManageService = medicalRecordDataManageService;
	}

	@Override
	public Integer call() throws Exception {
		Integer totalCount = 0;
		ShandongHomepageExcelDTO homepageData = null;
		for (String guid : guidList) {
			// 查询病案json
			Map<String, Object> jsonMap = medicalRecordDataManageService.getMedicalRecordMapByGuid(guid);
			logger.info("线程：{}，正在处理guid为:{}的数据", Thread.currentThread().getName(), guid);
    
			// 初始化基本信息
			handleHomepageBaiscData(jsonMap);
			
			// 处理诊断信息
			handleDiagInfo(jsonMap);
			

			// 处理护理记录
			handleNurseInfo(jsonMap);
			
			// 处理手术信息
			hadleOperationInfo(jsonMap);
			
			// 处理费用信息
			hadleCostInfo(jsonMap);
			
			// 处理输血信息
			handleInfusionBloodInfo(jsonMap);
			
			// 处理医师信息
			handleDoctorInfo(jsonMap);
			
			// 处理ICU信息
			handleIcuInfo(jsonMap);
			
			// 处理转科信息
			handleTransferDeptInfo(jsonMap);
			
			
			totalCount++;

		}
		
			// 查询病案json
//			Map<String, Object> jsonMap = medicalRecordDataManageService.getMedicalRecordMapByGuid("bf57ae4486de436fb45ab15d305b7e39");
//			
//		    System.out.println("+++"+jsonMap);
//		    
//			// 初始化基本信息
//			handleHomepageBaiscData(jsonMap);
//			
//			// 处理诊断信息
//			handleDiagInfo(jsonMap);
//			
//
//			// 处理护理记录
//			handleNurseInfo(jsonMap);
//			
//			// 处理手术信息
//			hadleOperationInfo(jsonMap);
//			
//			// 处理费用信息
//			hadleCostInfo(jsonMap);
//			
//			// 处理输血信息
//			handleInfusionBloodInfo(jsonMap);
//			
//			// 处理医师信息
//			handleDoctorInfo(jsonMap);
//			
//			// 处理ICU信息
//			handleIcuInfo(jsonMap);
//			
//			// 处理转科信息
//			handleTransferDeptInfo(jsonMap);
//			
			
			totalCount++;

		
		return totalCount;
	}

	/**
	 * 处理转科数据
	 * @param jsonMap
	 */
	private void handleTransferDeptInfo(Map<String, Object> jsonMap) {
		Map<String, Object> transferDeptInfo = MapUtils.getMap(jsonMap, "transferDeptInfo");
		if (MapUtils.isEmpty(transferDeptInfo)) {
			return;
		}
	
		String visitGuid = MapUtils.getString(transferDeptInfo, "visitGuid");
		
		List<MedicalRecordTurn> turnList = new ArrayList<>();
		List<Map<String,Object>> transferDeptRecords = (List<Map<String, Object>>) MapUtils.getObject(transferDeptInfo, "transferDeptRecords");
		if(org.apache.commons.collections4.CollectionUtils.isNotEmpty(transferDeptRecords)) {
			MedicalRecordTurn medicalRecordTurn = null;
			int index = 1;
			for (Map<String, Object> map : transferDeptRecords) {
				medicalRecordTurn = new MedicalRecordTurn();
				medicalRecordTurn.setVisitGuid(visitGuid);
				medicalRecordTurn.setTurnOut(MapUtils.getString(map, "outDeptCode"));
				medicalRecordTurn.setTurnIn(MapUtils.getString(map, "inDeptCode"));
				medicalRecordTurn.setOrderNo(index);
				medicalRecordTurn.setTurnReason(MapUtils.getString(map, "transferDeptRemarks"));
				String turnTimeStr = MapUtils.getString(map, "transferDeptDateTime");
				if(StringUtils.isNotEmpty(turnTimeStr)) {
					try {
						medicalRecordTurn.setTurnTime(DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", turnTimeStr));
					} catch (ParseException e) {
						e.printStackTrace();
					}
				}
				turnList.add(medicalRecordTurn);
				index++;
			}
		}
		if(CollectionUtils.isNotEmpty(turnList)) {
			medicalRecordDataManageService.saveOrUpdateTurn(turnList,visitGuid);
		}
		
		
	}

	/**
	 * 处理ICU信息
	 * @param jsonMap
	 */
	private void handleIcuInfo(Map<String, Object> jsonMap) {
		Map<String, Object> cureInfoMap = MapUtils.getMap(jsonMap, "cureInfo");
		if (MapUtils.isEmpty(cureInfoMap)) {
			return;
		}
		List<MedicalRecordIcu> icuList = new ArrayList<>();
		MedicalRecordIcu icu = null;
		String visitGuid = MapUtils.getString(cureInfoMap, "visitGuid");
		for (int i=1;i<=3;i++) {
			String intensiveCareUnitName = MapUtils.getString(cureInfoMap,"intensiveCareUnit"+i+"Name");
			String intensiveCareUnitCode = MapUtils.getString(cureInfoMap,"intensiveCareUnit"+i+"Code");
			String startTime = MapUtils.getString(cureInfoMap, "intensiveCareUnit"+i+"StartTime");
			String endTime = MapUtils.getString(cureInfoMap, "intensiveCareUnit"+i+"EndTime");
			if(StringUtils.isEmpty(startTime) && StringUtils.isEmpty(endTime)) {
				continue;
			}
			icu = new MedicalRecordIcu();
			icu.setVisitGuid(visitGuid);
			icu.setType(intensiveCareUnitName);
			icu.setTypeCode(intensiveCareUnitCode);
			if(StringUtils.isNotBlank(startTime) && !"null".equals(startTime)) {
				try {
					icu.setInTime(DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", startTime));
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if(StringUtils.isNotBlank(endTime) && !"null".equals(endTime)) {
				try {
					icu.setOutTime(DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", endTime));
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			icu.setDuration(MapUtils.getDouble(cureInfoMap, "intensiveCareUnit"+i+"Hour"));
			icuList.add(icu);
		}
		
		if(CollectionUtils.isNotEmpty(icuList)) {
			medicalRecordDataManageService.saveOrUpdateICU(icuList,visitGuid);
		}
	}

	/**
	 * 处理人员信息
	 * @param jsonMap
	 */
	private void handleDoctorInfo(Map<String, Object> jsonMap) {
		Map<String, Object> cureInfoMap = MapUtils.getMap(jsonMap, "cureInfo");
		if (MapUtils.isEmpty(cureInfoMap)) {
			return;
		}

		String visitGuid = MapUtils.getString(cureInfoMap, "visitGuid");
		List<Map<String, Object>> medicalWorks = (List<Map<String, Object>>) MapUtils.getObject(cureInfoMap,
				"cureWorkers");

		if (CollectionUtils.isNotEmpty(medicalWorks)) {
			List<MedicalRecordDoctor> doctorList = new ArrayList<>();
			MedicalRecordDoctor medicalRecordDoctor = null;
			for (Map<String, Object> medicalWork : medicalWorks) {
				
				String professionTitleName = MapUtils.getString(medicalWork, "professionTitleName");
				String professionTitleCode = MapUtils.getString(medicalWork, "professionTitleCode");
				String medicalWorkerName = MapUtils.getString(medicalWork, "medicalWorkerName");
				String medicalWorkerCode = MapUtils.getString(medicalWork, "medicalWorkerCode");
				
				if(StringUtils.isEmpty(medicalWorkerName) && StringUtils.isEmpty(medicalWorkerCode)) {
					continue;
				}
				
					
				medicalRecordDoctor = new MedicalRecordDoctor();
				medicalRecordDoctor.setVisitGuid(visitGuid);
				medicalRecordDoctor.setDoctorTypeCode(professionTitleCode);
				medicalRecordDoctor.setDoctorTypeName(professionTitleName);
				medicalRecordDoctor.setDoctorCode(medicalWorkerCode);
				medicalRecordDoctor.setDoctorName(medicalWorkerName);
				doctorList.add(medicalRecordDoctor);
			}
			
			if(CollectionUtils.isNotEmpty(doctorList)) {
				medicalRecordDataManageService.saveOrUpdateDoctor(doctorList,visitGuid);
			}

		}

	}

	/**
	 * 处理输血信息
	 * @param jsonMap
	 * @param homepageData
	 */
	private void handleInfusionBloodInfo(Map<String, Object> jsonMap) {
		Map<String, Object> infusionBloodInfo = MapUtils.getMap(jsonMap, "infusionBloodInfo");
		if (MapUtils.isEmpty(infusionBloodInfo)) {
			return;
		}
		

		
		// 输血记录
		List<Map<String,Object>> infusionBloodRecords = (List<Map<String, Object>>) MapUtils.getObject(infusionBloodInfo, "infusionBloodRecords");
		String visitGuid = MapUtils.getString(infusionBloodInfo, "visitGuid");
		if(CollectionUtils.isNotEmpty(infusionBloodRecords)) {
			List<MedicalRecordTransfusion> list = new ArrayList<>();
			MedicalRecordTransfusion transfusion = null;
			for (Map<String, Object> infusionBloodRecord : infusionBloodRecords) {
				transfusion = new MedicalRecordTransfusion();
				transfusion.setVisitGuid(visitGuid);
				String transTimeStr = MapUtils.getString(infusionBloodRecord, "bleedingDateTime");
				if(StringUtils.isNotBlank(transTimeStr)&& !"null".equals(transTimeStr)) {
					try {
						transfusion.setTransfusionTime(DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", transTimeStr));
					} catch (ParseException e) {
						logger.error("输血时间转换失败,异常信息:{}",e.getMessage());
						e.printStackTrace();
					}
				}
				transfusion.setBloodTypeCode(MapUtils.getString(infusionBloodRecord, "infusionBloodTypeCode"));
				transfusion.setBloodType(MapUtils.getString(infusionBloodRecord, "infusionBloodTypeName"));
				
				List<Map<String,Object>> infusionBloodElements = (List<Map<String, Object>>) MapUtils.getObject(infusionBloodRecord, "infusionBloodElements");
				for (Map<String, Object> infusionBloodElement : infusionBloodElements) {
					String bloodElementCode = MapUtils.getString(infusionBloodElement, "bloodElementCode");
					double bloodElementVolume = MapUtils.getDoubleValue(infusionBloodElement, "bloodElementVolume");
					// 红细胞
					if("B0001".equals(bloodElementCode)) {
						transfusion.setRedCell(bloodElementVolume);
					// 白细胞
					}else if("B0002".equals(bloodElementCode)) {
						transfusion.setWhiteBloodCell(bloodElementVolume);
					//血小板	
					}else if("B0003".equals(bloodElementCode)) {
						transfusion.setPlatelet(bloodElementVolume);
					// 血浆
					}else if("B0004".equals(bloodElementCode)) {
						transfusion.setPlasma(bloodElementVolume);
					// 全血	
					}else if("B0005".equals(bloodElementCode)) {
						transfusion.setWhiteBloodCell(bloodElementVolume);
					// 自体血回输
					}else if("B0006".equals(bloodElementCode)) {
						transfusion.setAutohemic(bloodElementVolume);
					}else {
						transfusion.setOtherBlood(bloodElementVolume);
					}
				}
				
				list.add(transfusion);
				
			}
			
			if(CollectionUtils.isNotEmpty(list)) {
				medicalRecordDataManageService.saveOrUpdateTransfusion(list,visitGuid);
			}
		}
		
		
		
		
	}

	/**
	 * 处理费用信息
	 * 
	 * @param jsonMap
	 * @param homepageData
	 */
	private void hadleCostInfo(Map<String, Object> jsonMap) {
		Map<String, Object> costInfoMap = MapUtils.getMap(jsonMap, "costInfo");
		if (MapUtils.isEmpty(costInfoMap)) {
			return;
		}
		MedicalRecordCost cost = new MedicalRecordCost();
		cost.setVisitGuid(MapUtils.getString(costInfoMap, "visitGuid"));
		// 住院总费用
		String ZFY = ObjectUtils.getStringValue(costInfoMap.get("totalCost"));
		if(StringUtils.isNotBlank(ZFY)) {
			cost.setCost01(new BigDecimal(ZFY));
		}
		
		// 住院总费用其中自付金额
		String ZFJE = ObjectUtils.getStringValue(costInfoMap.get("selfCost"));
		if(StringUtils.isNotBlank(ZFJE)) {
			cost.setCost02(new BigDecimal(ZFJE));
		}
		
		List<Map<String, Object>> costRecords = (List<Map<String, Object>>) MapUtils.getObject(costInfoMap,
				"costRecords");
		if (CollectionUtils.isNotEmpty(costRecords)) {
			for (Map<String, Object> costRecord : costRecords) {

				String medicalCostTypeCode = MapUtils.getString(costRecord, "medicalCostTypeCode");
				String money = MapUtils.getString(costRecord, "costMoney");
				if(StringUtils.isEmpty(money)) {
					continue;
				}
				BigDecimal moneyDecimal = new BigDecimal(money);
				// 1.一般医疗服务费
				if ("C01001".equals(medicalCostTypeCode)) {
					cost.setCost03(moneyDecimal);
				// 2.一般治疗操作费	
				}else if("C01002".equals(medicalCostTypeCode)) {
					cost.setCost04(moneyDecimal);
				// 3.护理费	
				}else if("C01003".equals(medicalCostTypeCode)) {
					cost.setCost05(moneyDecimal);
				// 4.综合医疗服务类其他费用	
				}else if("C01999".equals(medicalCostTypeCode)) {
					cost.setCost06(moneyDecimal);
				// 5.病理诊断费
				}else if("C02001".equals(medicalCostTypeCode)) {
					cost.setCost07(moneyDecimal);
				// 6.实验室诊断费
				}else if("C02002".equals(medicalCostTypeCode)) {
					cost.setCost08(moneyDecimal);
				// 7.影像学诊断费
				}else if("C02003".equals(medicalCostTypeCode)) {
					cost.setCost09(moneyDecimal);
				// 8.临床诊断项目费	
				}else if("C02004".equals(medicalCostTypeCode)) {
					cost.setCost10(moneyDecimal);
				// 9.非手术治疗项目费	
				}else if("C03001".equals(medicalCostTypeCode)) {
					cost.setCost11(moneyDecimal);
				// 其中：临床物理治疗费	
				}else if("C03002".equals(medicalCostTypeCode)) {
					cost.setCost12(moneyDecimal);
				// 10.手术治疗费	
				}else if("C03003".equals(medicalCostTypeCode)) {
					cost.setCost13(moneyDecimal);
				// 其中：麻醉费
				}else if("C03004".equals(medicalCostTypeCode)) {
					cost.setCost14(moneyDecimal);
				// 其中：手术费	
				}else if("C03005".equals(medicalCostTypeCode)) {
					cost.setCost15(moneyDecimal);
				// 11.康复费	KFF
				}else if("C04001".equals(medicalCostTypeCode)) {
					cost.setCost16(moneyDecimal);
				// 12.中医治疗费	ZYZLF
				}else if("C05001".equals(medicalCostTypeCode)) {
					cost.setCost17(moneyDecimal);
				// 13.西药费	XYF
				}else if("C06001".equals(medicalCostTypeCode)) {
					cost.setCost18(moneyDecimal);
				// 其中：抗菌药物费	KJYWF
				}else if("C06002".equals(medicalCostTypeCode)) {
					cost.setCost19(moneyDecimal);
				// 14.中成药费	ZCYF
				}else if("C07001".equals(medicalCostTypeCode)) {
					cost.setCost20(moneyDecimal);
				// 15.中草药费	ZCYF1
				}else if("C07002".equals(medicalCostTypeCode)) {
					cost.setCost21(moneyDecimal);
				// 16.血费	XF
				}else if("C08001".equals(medicalCostTypeCode)) {
					cost.setCost22(moneyDecimal);
				// 17.白蛋白类制品费	BDBLZPF
				}else if("C08002".equals(medicalCostTypeCode)) {
					cost.setCost23(moneyDecimal);
				// 18.球蛋白类制品费	QDBLZPF
				}else if("C08003".equals(medicalCostTypeCode)) {
					cost.setCost24(moneyDecimal);
				// 19.凝血因子类制品费	NXYZLZPF
				}else if("C08004".equals(medicalCostTypeCode)) {
					cost.setCost25(moneyDecimal);
				// 20.细胞因子类制品费	
				}else if("C08005".equals(medicalCostTypeCode)) {
					cost.setCost26(moneyDecimal);
				// 21.检查用一次性医用材料费	HCYYCLF
				}else if("C09001".equals(medicalCostTypeCode)) {
					cost.setCost27(moneyDecimal);
				// 22.治疗用一次性医用材料费	YYCLF
				}else if("C09002".equals(medicalCostTypeCode)) {
					cost.setCost28(moneyDecimal);
				// 23.手术用一次性医用材料费	YCXYYCLF	
				}else if("C09003".equals(medicalCostTypeCode)) {
					cost.setCost29(moneyDecimal);
				// 24.其他费：	QTF
				}else if("C99999".equals(medicalCostTypeCode)) {
					cost.setCost30(moneyDecimal);
				}
			}
		}
		medicalRecordDataManageService.saveOrUpdateCost(cost);

	}

	/**
	 * 处理手术相关数据信息
	 * 
	 * @param jsonMap
	 * @param homepageData
	 */
	private void hadleOperationInfo(Map<String, Object> jsonMap) {
		List<MedicalRecordOperation> operationList = new ArrayList<>();
		Map<String, Object> operationInfoMap = MapUtils.getMap(jsonMap, "operateInfo");
		if (MapUtils.isEmpty(operationInfoMap)) {
			return;
		}
		String visitGuid = MapUtils.getString(operationInfoMap, "visitGuid");
		// 获取手术信息集合
		List<Map<String, Object>> operateRecords = (List<Map<String, Object>>) MapUtils.getObject(operationInfoMap,
				"operateRecords");
		if (CollectionUtils.isEmpty(operateRecords)) {
			return;
		}

		int opsIndex = 1;
		MedicalRecordOperation medicalRecordOperation = null;
		for (Map<String, Object> operateRecord : operateRecords) {
			medicalRecordOperation = new MedicalRecordOperation();
			medicalRecordOperation.setVisitGuid(visitGuid);
			medicalRecordOperation.setOpsOrder(opsIndex);
			// 手术开始时间
			String opsStartStr = MapUtils.getString(operateRecord, "operateStartDate");
			if(StringUtils.isNotEmpty(opsStartStr) && !"null".equals(opsStartStr)) {
				try {
					medicalRecordOperation.setOpsStart(DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", opsStartStr));
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			// 手术结束时间
			String opsEndStr = MapUtils.getString(operateRecord, "operateEndDate");
			if(StringUtils.isNotEmpty(opsEndStr) && !"null".equals(opsEndStr)) {
				try {
					medicalRecordOperation.setOpsEnd(DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", opsEndStr));
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			// 手术持续时间
			medicalRecordOperation.setOpsTime(MapUtils.getDouble(operateRecord, "operateDurationTime"));
			// 医生手术操作编码
			medicalRecordOperation.setDoctorOpsCode(MapUtils.getString(operateRecord, "operateOriginalCode"));
			// 医生手术操作名称
			medicalRecordOperation.setDoctorOpsName(MapUtils.getString(operateRecord, "operateOriginalDesc"));
			// 手术编码
			medicalRecordOperation.setOpsCode(MapUtils.getString(operateRecord, "operateCode"));
			medicalRecordOperation.setOperation(MapUtils.getString(operateRecord, "operateName"));
			// 手术级别
			medicalRecordOperation.setOpsLevel(MapUtils.getString(operateRecord, "opsLevelName"));
			medicalRecordOperation.setOpsLevelCode(MapUtils.getString(operateRecord, "opsLevelCode"));
			// 切口等级
			medicalRecordOperation.setOpsIncision(MapUtils.getString(operateRecord, "incisionLevelName"));
			medicalRecordOperation.setOpsIncisionCode(MapUtils.getString(operateRecord, "incisionLevelCode"));
			// 愈合等级
			medicalRecordOperation.setOpsHeal(MapUtils.getString(operateRecord, "cicatrizeTypeName"));
			medicalRecordOperation.setOpsHealCode(MapUtils.getString(operateRecord, "cicatrizeTypeCode"));
			// 手术类别
			medicalRecordOperation.setOpsMark(MapUtils.getString(operateRecord, "operatMarkName"));
			medicalRecordOperation.setOpsMarkCode(MapUtils.getString(operateRecord, "operatMarkCode"));
			
			// 麻醉开始时间
			String anaStartStr = MapUtils.getString(operateRecord, "anesthesiaStartTime");
			if(StringUtils.isNotEmpty(anaStartStr) && !"null".equals(anaStartStr)) {
				try {
					medicalRecordOperation.setAnaStart(DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", anaStartStr));
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			// 麻醉结束时间
			String anaEndStr = MapUtils.getString(operateRecord, "anesthesiaEndTime");
			if(StringUtils.isNotEmpty(anaEndStr) && !"null".equals(anaEndStr)) {
				try {
					medicalRecordOperation.setAnaEnd(DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", anaEndStr));
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			
			// 麻醉分级
			medicalRecordOperation.setAnaCode(MapUtils.getString(operateRecord, "anaesthesiaLevelCode"));
			medicalRecordOperation.setAna(MapUtils.getString(operateRecord, "anaesthesiaLevelName"));
			
			// 非计划再次手术
			medicalRecordOperation.setOpsNature(MapUtils.getString(operateRecord, "isUnPlanReOperateName"));
			medicalRecordOperation.setOpsNatureCode(MapUtils.getString(operateRecord, "isUnPlanReOperateCode"));
			
			// 麻醉方式
			medicalRecordOperation.setAnesthesia(MapUtils.getString(operateRecord, "anaesthesiaTypeName"));
			medicalRecordOperation.setAnesthesiaCode(MapUtils.getString(operateRecord, "anaesthesiaTypeCode"));
			
			List<Map<String, Object>> operateWorkers = (List<Map<String, Object>>) MapUtils.getObject(operateRecord,
					"operateWorkers");

		
			// 手术医师
			if (CollectionUtils.isNotEmpty(operateWorkers)) {

				for (Map<String, Object> operateWorker : operateWorkers) {
					String professionTitleCode = MapUtils.getString(operateWorker, "professionTitleCode");
					String professionTitleName = MapUtils.getString(operateWorker, "professionTitleName");
					String medicalWorkerName = MapUtils.getString(operateWorker, "medicalWorkerName");
					String medicalWorkerCode = MapUtils.getString(operateWorker, "medicalWorkerCode");
					if(StringUtils.isEmpty(medicalWorkerCode) || StringUtils.isEmpty(medicalWorkerName)) {
						continue;
					}
				
					// 手术操作术者
					if ("A5001".equals(professionTitleCode)) {
						medicalRecordOperation.setOpsDoctor(medicalWorkerName);
						medicalRecordOperation.setOpsDoctorCode(medicalWorkerCode);
						// 手术操作Ⅰ助
					} else if ("A5003".equals(professionTitleCode)) {
						medicalRecordOperation.setOpsAss1(medicalWorkerName);
						medicalRecordOperation.setOpsAssCode1(medicalWorkerCode);
						// 手术操作Ⅱ助
					} else if ("A5004".equals(professionTitleCode)) {
						medicalRecordOperation.setOpsAss2(medicalWorkerName);
						medicalRecordOperation.setOpsAssCode2(medicalWorkerCode);
						// 麻醉医师
					} else if ("A5002".equals(professionTitleCode)) {
						medicalRecordOperation.setAnaDoctor(medicalWorkerName);
						medicalRecordOperation.setAnaDoctorCode(medicalWorkerCode);
					} else if ("A5007".equals(professionTitleCode)) {
						
					} else if ("A5008".equals(professionTitleCode)) {
						
					} else if ("A5009".equals(professionTitleCode)) {
						
					}
				}

			}
			operationList.add(medicalRecordOperation);
			opsIndex++;
		}
		
		if(CollectionUtils.isNotEmpty(operationList)) {
			medicalRecordDataManageService.saveOrUpdateOperation(operationList,visitGuid);
		}
		
	}

	/**
	 * 处理护理天数
	 * 
	 * @param jsonMap
	 * @param homepageData
	 */
	private void handleNurseInfo(Map<String, Object> jsonMap) {
		Map<String, Object> nurseInfoMap = MapUtils.getMap(jsonMap, "nurseInfo");
		if (MapUtils.isNotEmpty(nurseInfoMap)) {
			MedicalRecordNurse nurse = new MedicalRecordNurse();
			nurse.setVisitGuid(MapUtils.getString(nurseInfoMap, "visitGuid"));
			// 病危天数
			nurse.setCriticalDay(MapUtils.getInteger(nurseInfoMap, "criticalDayNumber"));
			// 病重天数
			nurse.setSeriousIllnessDay(MapUtils.getInteger(nurseInfoMap, "sickDayNumber"));
			// 特级护理天数
			nurse.setSpecialNurseDay(MapUtils.getInteger(nurseInfoMap, "specialNurseDayNumber"));
			// 特级护理小时数
			nurse.setSpecialNurseHour(MapUtils.getInteger(nurseInfoMap, "specialNurseHourNumber"));
			// 一级护理天数
			nurse.setFirstNurseDay(MapUtils.getInteger(nurseInfoMap, "firstLevelNurseDayNumber"));
			// 二级护理天数
			nurse.setSecondNurseDay(MapUtils.getInteger(nurseInfoMap, "secondLevelNurseDayNumber"));
			// 三级护理天数
			nurse.setThirdNurseDay(MapUtils.getInteger(nurseInfoMap, "threeLevelNurseDayNumber"));
			
			medicalRecordDataManageService.saveOrUpdateNurse(nurse);
		}
	}

	public List<String> getGuidList() {
		return guidList;
	}

	public void setGuidList(List<String> guidList) {
		this.guidList = guidList;
	}

	public MedicalRecordDataManageService getMedicalRecordDataManageService() {
		return medicalRecordDataManageService;
	}

	public void setMedicalRecordDataManageService(MedicalRecordDataManageService medicalRecordDataManageService) {
		this.medicalRecordDataManageService = medicalRecordDataManageService;
	}

	/**
	 * 设置病案初始化数据
	 */
	public void initHomepageData(ShandongHomepageExcelDTO shandongHomepageExcelDTO) {
		// 组织机构代码
		shandongHomepageExcelDTO.setZZJGDM(HomepageConstatnt.ORGANIZATION_ID);
		// 组织机构名称
		shandongHomepageExcelDTO.setJGMC(HomepageConstatnt.ORGANIZATION);
		// 对应的系统登录用户名
		shandongHomepageExcelDTO.setUSERNAME(HomepageConstatnt.USER_NAME);
	}

	/**
	 * 处理病案基本信息数据
	 * 
	 * @param jsonMap
	 * @param shandongHomepageExcelDTO
	 */
	public void handleHomepageBaiscData(Map<String, Object> jsonMap) {
		
		MedicalRecordBasic basic = null;
		
		// 基本信息
		Map<String, Object> basicInfoMap = MapUtils.getMap(jsonMap, "basicInfo");
		if (MapUtils.isEmpty(basicInfoMap)) {
			return;
		}
		basic = new MedicalRecordBasic();
		basic.setVisitGuid(MapUtils.getString(basicInfoMap, "visitGuid"));
		// 医疗付款方式
		String medicalPayTypeCode = MapUtils.getString(basicInfoMap, "medicalPayTypeCode");
		if(StringUtils.isNotBlank(medicalPayTypeCode)) {
			basic.setPayTypeCode(medicalPayTypeCode);
		}
		// 唯一标识
		basic.setOnlyId(MapUtils.getString(basicInfoMap, "onlyId"));
		// 健康卡号
		basic.setHealthNo(MapUtils.getString(basicInfoMap, "medicalHealthNumber"));
		// 住院次数
		basic.setVisitNumber(MapUtils.getInteger(basicInfoMap, "visitNumber"));
		// 病案号
		basic.setMrId(MapUtils.getString(basicInfoMap, "mrId"));
		// 姓名
		basic.setPatientName(MapUtils.getString(basicInfoMap, "patientName"));
		// 性别
		basic.setSexCode(MapUtils.getString(basicInfoMap, "sexCode"));
		// 出生日期
		String birthdayStr = MapUtils.getString(basicInfoMap, "birthday");
		if (StringUtils.isNotBlank(birthdayStr) && !birthdayStr.equals("null")) {
			try {
				basic.setBirthday(DateUtil.dateParse("yyyy-MM-dd", birthdayStr));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		// 年龄 - 岁
		basic.setAgeYear( MapUtils.getInteger(basicInfoMap, "yearOfAge"));
		// 年龄 - 月
		basic.setAgeMonth( MapUtils.getInteger(basicInfoMap, "yearOfMonth"));
		// 年龄 - 天
		basic.setAgeDay( MapUtils.getInteger(basicInfoMap, "yearOfDay"));
		
		// 国籍
		basic.setNationalityCode(MapUtils.getString(basicInfoMap, "nationalityCode"));
		
	

		Map<String, Object> birthRegionalismMap = MapUtils.getMap(basicInfoMap, "birthRegionalism");
		if (MapUtils.isNotEmpty(birthRegionalismMap)) {
			// 出生地_省
			basic.setBirthProvinceCode(MapUtils.getString(birthRegionalismMap, "provinceCode"));
			// 出生地—市
			basic.setBirthCityCode(MapUtils.getString(birthRegionalismMap, "cityCode"));
			// 出生地—区县
			basic.setBirthCountyCode(MapUtils.getString(birthRegionalismMap, "countyCode"));
			// 出生地—详细地址
			basic.setBirthAddress(MapUtils.getString(birthRegionalismMap, "fullAddress"));
		}

		// 籍贯—省
		Map<String, Object> nativePlaceRegionalismMap = MapUtils.getMap(basicInfoMap, "nativePlaceRegionalism");
		if (MapUtils.isNotEmpty(nativePlaceRegionalismMap)) {
			// 籍贯—省
			basic.setNativeProvinceCode(MapUtils.getString(nativePlaceRegionalismMap, "provinceCode"));
			// 籍贯—市
			basic.setNativeCityCode(MapUtils.getString(nativePlaceRegionalismMap, "cityCode"));
			// 籍贯—区
			basic.setNativeCountyCode(MapUtils.getString(nativePlaceRegionalismMap, "countyCode"));
			// 籍贯—地址
			basic.setNativeAddress(MapUtils.getString(nativePlaceRegionalismMap, "countyCode"));

		}
		// 民族
		basic.setNationCode(MapUtils.getString(basicInfoMap, "nationCode"));
		// 身份证件类别
		basic.setCertificateTypeCode(MapUtils.getString(basicInfoMap, "documentTypeCode"));
		// 身份证号
		basic.setIdNumber(MapUtils.getString(basicInfoMap, "idNumber"));
		// 职业
		basic.setProfessionCode(MapUtils.getString(basicInfoMap, "professionCode"));
		// 婚姻
		basic.setMarriageCode(MapUtils.getString(basicInfoMap, "marriageCode"));

		// 现住址
		Map<String, Object> permanentAddressRegionalismMap = MapUtils.getMap(basicInfoMap,
				"permanentAddressRegionalism");
		if (MapUtils.isNotEmpty(permanentAddressRegionalismMap)) {
			// 现住址—省
			basic.setPresentProvinceCode(MapUtils.getString(permanentAddressRegionalismMap, "provinceCode"));
			// 现住址—市
			basic.setPresentCityCode(MapUtils.getString(permanentAddressRegionalismMap, "cityCode"));
			// 现住址—区县
			basic.setPresentCountyCode(MapUtils.getString(permanentAddressRegionalismMap, "countyCode"));
			// 现住址—详细地址
			basic.setPresentAddress(MapUtils.getString(permanentAddressRegionalismMap, "fullAddress"));

		}
		// 电话
		basic.setPresentPhone(MapUtils.getString(basicInfoMap, "permanentAddressPhone"));
		// 移动电话
		basic.setPresentMobile(MapUtils.getString(basicInfoMap, "permanentAddressMobilePhone"));
		// 邮编
		basic.setPresentPostalCode(MapUtils.getString(basicInfoMap, "permanentAddressPostCode"));

		// 户口地址
		Map<String, Object> registeredAddressRegionalismMap = MapUtils.getMap(basicInfoMap,
				"registeredAddressRegionalism");
		if (MapUtils.isNotEmpty(registeredAddressRegionalismMap)) {
			// 户口地址—省
			basic.setRegisteredProvinceCode(MapUtils.getString(registeredAddressRegionalismMap, "provinceCode"));
			// 户口地址—市
			basic.setRegisteredCityCode(MapUtils.getString(registeredAddressRegionalismMap, "cityCode"));
			// 户口地址—区县
			basic.setRegisteredCountyCode(MapUtils.getString(registeredAddressRegionalismMap, "countyCode"));
			// 户口地址
			basic.setRegisteredAddress(MapUtils.getString(registeredAddressRegionalismMap, "fullAddress"));
			// 户口邮编
			basic.setRegisteredPostalCode(MapUtils.getString(basicInfoMap, "registeredAddressPostCode"));
		}


		// 工作单位名称
		basic.setWorkUnit(MapUtils.getString(basicInfoMap, "workUnitName"));

		// 工作单位
		Map<String, Object> workUnitRegionalismMap = MapUtils.getMap(basicInfoMap, "workUnitRegionalism");
		if (MapUtils.isNotEmpty(workUnitRegionalismMap)) {
			// 工作单位及地址—省
			basic.setWorkUnitProvicneCode(MapUtils.getString(workUnitRegionalismMap, "provinceCode"));

			// 工作单位及地址—市
			basic.setWorkUnitCityCode(MapUtils.getString(workUnitRegionalismMap, "cityCode"));

			// 工作单位及地址—区县
			basic.setWorkUnitCountyCode(MapUtils.getString(workUnitRegionalismMap, "countyCode"));
			// 工作单位及地址—详细地址
			basic.setWorkUnitAddress(MapUtils.getString(workUnitRegionalismMap, "fullAddress"));

		}
		// 工作单位电话
		basic.setWorkUnitPhone(MapUtils.getString(basicInfoMap, "workUnitPhone"));
		// 工作单位邮政编码
		basic.setWorkUnitPostalCode(MapUtils.getString(basicInfoMap, "workUnitPostCode"));
		// 联系人姓名
		basic.setLinkmanName(MapUtils.getString(basicInfoMap, "linkManName"));
		// 联系人关系
		basic.setLinkmanRelationCode(MapUtils.getString(basicInfoMap, "linkManRelativeRelationCode"));
	
		

		Map<String, Object> linkManAddressRegionalismMap = MapUtils.getMap(basicInfoMap, "linkManAddressRegionalism");
		if (MapUtils.isNotEmpty(linkManAddressRegionalismMap)) {
			// 联系人地址—省
			basic.setLinkmanProvinceCode(MapUtils.getString(linkManAddressRegionalismMap, "provinceCode"));

			// 联系人地址—市
			basic.setLinkmanCityCode(MapUtils.getString(linkManAddressRegionalismMap, "cityCode"));

			// 联系人地址—区县
			basic.setLinkmanCountyCode(MapUtils.getString(linkManAddressRegionalismMap, "countyCode"));

			// 联系人地址—详细地址
			basic.setLinkmanAddress(MapUtils.getString(linkManAddressRegionalismMap, "fullAddress"));
		}

		// 联系人电话
		basic.setLinkmanPhone(MapUtils.getString(basicInfoMap, "linkManPhone"));

		// 入院途径
		basic.setInHospitalTypeCode( MapUtils.getString(basicInfoMap, "inHospitalTypeCode"));
		
		// 转诊医疗机构名称
		basic.setReceiveUnit(MapUtils.getString(basicInfoMap, "shiftToUnitName"));
		String inTime = MapUtils.getString(basicInfoMap, "inHospitalDateTime");

		if (StringUtils.isNotBlank(inTime) && !"null".equals(inTime) ) {
			try {
				Date inHospitalTime = DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", inTime);
				// 入院时间
				basic.setInTime(inHospitalTime);
			} catch (Exception e) {
				e.printStackTrace();
				logger.error("入院时间字符串转时间失败,异常信息:{}", e.getMessage());
			}
		}

		// 入院科室
		String inDeptCode = MapUtils.getString(basicInfoMap, "inDeptCode");
		if(StringUtils.isNotEmpty(inDeptCode)) {
			basic.setInDeptCode(inDeptCode);
		}
		

		// 入院病房
		basic.setInHouseName(MapUtils.getString(basicInfoMap, "inHospitalHouseName"));

		// 出院日期
		String outTimeStr = MapUtils.getString(basicInfoMap, "outHospitalDateTime");

		if (StringUtils.isNotBlank(outTimeStr) && !"null".equals(outTimeStr)) {

			try {
				// 出院日期
				Date outHospitalTime = DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", outTimeStr);
				// 出院日期
				basic.setOutTime(outHospitalTime);
				// 入院时间 - 时
			} catch (Exception e) {
				e.printStackTrace();
				logger.error("出院时间字符串转时间失败,异常信息:{}", e.getMessage());
			}
		}

		// 出院科别
		String outDeptCode = MapUtils.getString(basicInfoMap, "outDeptCode");
		if(StringUtils.isNotEmpty(outDeptCode)) {
			basic.setOutDeptCode(outDeptCode);
		}
		

		// 实际住院天数
		basic.setHod(MapUtils.getInteger(basicInfoMap, "inHospitalDayNumber"));

		// 入院诊断确诊时间
		String diagConfirmedDateTimeStr = MapUtils.getString(basicInfoMap, "diagConfirmedDateTime");
		if (StringUtils.isNotBlank(diagConfirmedDateTimeStr) && !"null".equals(diagConfirmedDateTimeStr)) {

			try {
				// 出院日期
				Date diagConfirmedDateTime = DateUtil.dateParse("yyyy-MM-dd HH:mm:ss", diagConfirmedDateTimeStr);
				basic.setDiagnosisTime(diagConfirmedDateTime);

			} catch (Exception e) {
				e.printStackTrace();
				logger.error("入院后确诊时间字符串转时间失败,异常信息:{}", e.getMessage());
			}
		}

		// 有无药物过敏
		basic.setDrugAllergy(MapUtils.getString(basicInfoMap, "whetherDrugAllergyCode"));
		// 过敏药物
		basic.setAllergicDrug(MapUtils.getString(basicInfoMap, "drugAllergyDesc"));
		// 死亡患者尸检
		String SWHZSJ = MapUtils.getString(basicInfoMap, "autopsyCode");
		basic.setAutopsyCode(SWHZSJ);

		// 离院方式
		basic.setOutHospitalTypeCode(MapUtils.getString(basicInfoMap, "outHospitalTypeCode"));;

		Map<String, Object> cureInfoMap = MapUtils.getMap(jsonMap, "cureInfo");
		if (MapUtils.isNotEmpty(cureInfoMap)) {
	
			// abo血型
			basic.setAbo(MapUtils.getString(cureInfoMap, "abo"));
			// rh血型
			basic.setRh(MapUtils.getString(cureInfoMap, "abo"));
			// 新生儿入院类型
			basic.setNeonatalAdmissionTypeCode(MapUtils.getString(cureInfoMap, "neonatalAdmissionTypeCode"));
			
			// 新生儿出生体重（克）	XSECSTZ
			basic.setBabyBirthWeight(MapUtils.getDouble(cureInfoMap, "babyBirthWeight"));
			// 新生儿出生体重（克）2	XSECSTZ1
			basic.setBabyBirthWeight2(MapUtils.getDouble(cureInfoMap, "babyBirthWeight2"));
			// 新生儿出生体重（克）3	XSECSTZ2
			basic.setBabyBirthWeight3(MapUtils.getDouble(cureInfoMap, "babyBirthWeight3"));
			// 新生儿出生体重（克）4	XSECSTZ3
			basic.setBabyBirthWeight4(MapUtils.getDouble(cureInfoMap, "babyBirthWeight4"));
			// 新生儿出生体重（克）5	XSECSTZ4
			basic.setBabyBirthWeight5(MapUtils.getDouble(cureInfoMap, "babyBirthWeight5"));
			// 新生儿入院体重（克）	XSERYTZ
			basic.setBabyInWeight(MapUtils.getDouble(cureInfoMap, "babyInHospitalWeight"));

			//住院医疗类型:1.住院 2.日间手术
			basic.setInpatientMedicalTypeCode(MapUtils.getString(cureInfoMap, "inpatientMedicalTreatmentCode"));
			// 日间手术
			basic.setDaySurgery(MapUtils.getString(cureInfoMap, "isDaySurgeryCode"));
			// 抢救次数
			basic.setRescueTimes(MapUtils.getInteger(cureInfoMap, "rescueNumber"));
			// 抢救成功次数
			basic.setRescueSuccessTimes(MapUtils.getInteger(cureInfoMap, "rescueSucceedNumber"));
			// 院内会诊数
			basic.setInConsultationNumber(MapUtils.getInteger(cureInfoMap, "inConsultationNumber"));
			// 院外会诊数
			basic.setOutConsultationNumber(MapUtils.getInteger(cureInfoMap, "outConsultationNumber"));
			// 输液次数
			basic.setInfusionTimes(MapUtils.getInteger(cureInfoMap, "infusionTimes"));
			// 输液反应次数
			basic.setInfusionReactionTimes(MapUtils.getInteger(cureInfoMap, "infusionReactTimes"));
			// 是否随诊
			basic.setFollowUp(MapUtils.getString(cureInfoMap, "followUpClinicLimitCode"));
			// 随诊-天
			basic.setFollowUpDay(MapUtils.getInteger(cureInfoMap, "followUpClinicDayNumber"));
			// 随诊-周
			basic.setFollowUpWeek(MapUtils.getInteger(cureInfoMap, "followUpClinicWeekNumber"));
			// 随诊-月
			basic.setFollowUpMonth(MapUtils.getInteger(cureInfoMap, "followUpClinicMonthNumber"));
			// 随诊-年i
			basic.setFollowUpYear(MapUtils.getInteger(cureInfoMap, "followUpClinicYearNumber"));
			// 31天再住院计划
			basic.setRehospital31Plan(MapUtils.getString(cureInfoMap, "rehospitalAimOf31Code"));
			// 31天再住院目的
			basic.setRehospital31Aim(MapUtils.getString(cureInfoMap, "rehospitalAimOf31Name"));
			// 呼吸机使用-天
			basic.setRespiratorDay(MapUtils.getInteger(cureInfoMap, "invasiveVentilatorDay"));
			// 呼吸机使用-小时
			basic.setRespiratorHour(MapUtils.getInteger(cureInfoMap, "invasiveVentilatorHour"));
			// 呼吸机使用-分钟
			basic.setRespiratorMinute(MapUtils.getInteger(cureInfoMap, "invasiveVentilatorMinute"));
			
			// 颅脑损伤患者入院前昏迷时间（天）
			basic.setComaBeforeDay(MapUtils.getInteger(cureInfoMap, "dayOfBeforeInHospitalComa"));
			// 颅脑损伤患者入院前昏迷时间（小时）
			basic.setComaBeforeHour(MapUtils.getInteger(cureInfoMap, "hourOfBeforeInHospitalComa"));
			// 颅脑损伤患者入院前昏迷时间（分钟）
			basic.setComaAfterMinute(MapUtils.getInteger(cureInfoMap, "minuteOfBeforeInHospitalComa"));
			// 颅脑损伤患者入院后昏迷时间（天）
			basic.setComaAfterDay(MapUtils.getInteger(cureInfoMap, "dayOfAfterInHospitalComa"));
			// 颅脑损伤患者入院后昏迷时间（小时）
			basic.setComaAfterHour(MapUtils.getInteger(cureInfoMap, "hourOfAfterInHospitalComa"));
			// 颅脑损伤患者入院后昏迷时间（分钟）
			basic.setComaAfterMinute(MapUtils.getInteger(cureInfoMap, "minuteOfAfterInHospitalComa"));
			
			medicalRecordDataManageService.saveOrUpdateMedicalRecordBasic(basic);
		}
		
	}

	/**
	 * 处理诊断信息
	 * 
	 * @param jsonMap      json数据
	 * @param homepageData 首页数据信息
	 */
	@SuppressWarnings("unchecked")
	private void handleDiagInfo(Map<String, Object> jsonMap) {
		List<MedicalRecordDiagnoss> list = new ArrayList<>();
		MedicalRecordDiagnoss medicalRecordDiagnoss = null;
		// 从json中获取疾病信息
		Map<String, Object> diseaseDiagInfoMap = MapUtils.getMap(jsonMap, "diseaseDiagInfo");
		if (MapUtils.isEmpty(diseaseDiagInfoMap)) {
			return;
		}
		// 获取门诊信息
		Map<String, Object> outpatientDiagRecordMap = MapUtils.getMap(diseaseDiagInfoMap, "outpatientDiagRecord");
		String visitGuid = MapUtils.getString(diseaseDiagInfoMap, "visitGuid");
		if (MapUtils.isNotEmpty(outpatientDiagRecordMap)) {
			String outpatientDiagName = MapUtils.getString(outpatientDiagRecordMap, "diseaseDiagName");
			String outpatientDiagCode = MapUtils.getString(outpatientDiagRecordMap, "diseaseDiagCode");
			String diseaseDiagOriginalCode = MapUtils.getString(outpatientDiagRecordMap, "diseaseDiagOriginalCode");
			String diseaseDiagOriginalDesc = MapUtils.getString(outpatientDiagRecordMap, "diseaseDiagOriginalDesc");
			if(StringUtils.isNotBlank(outpatientDiagCode) || StringUtils.isNotBlank(diseaseDiagOriginalCode)) {
				medicalRecordDiagnoss = new MedicalRecordDiagnoss();
				medicalRecordDiagnoss.setVisitGuid(visitGuid);
				medicalRecordDiagnoss.setDiagTypeCode(MapUtils.getString(outpatientDiagRecordMap, "diagTypeCode"));
				medicalRecordDiagnoss.setDiagType(MapUtils.getString(outpatientDiagRecordMap, "diagTypeName"));
				medicalRecordDiagnoss.setDoctorDiag(diseaseDiagOriginalDesc);
				medicalRecordDiagnoss.setDoctorDiagCode(diseaseDiagOriginalCode);
				medicalRecordDiagnoss.setDiagCode(outpatientDiagCode);
				medicalRecordDiagnoss.setDiagName(outpatientDiagName);
				list.add(medicalRecordDiagnoss);
			}
			
		}

		// 主要诊断信息
		Map<String, Object> mainDiagRecordMap = MapUtils.getMap(diseaseDiagInfoMap, "mainDiagRecord");
		if (MapUtils.isNotEmpty(mainDiagRecordMap)) {
			String mainDiagName = ObjectUtils.getStringValue(mainDiagRecordMap.get("diseaseDiagName"));
			String mainDiagNameDesc = MapUtils.getString(mainDiagRecordMap, "diseaseDiagOriginalDesc");
			String mainDiagCode = ObjectUtils.getStringValue(mainDiagRecordMap.get("diseaseDiagCode"));
			String mainDiagCodeDesc = MapUtils.getString(mainDiagRecordMap, "diseaseDiagOriginalCode");
			if(StringUtils.isNotBlank(mainDiagCode) || StringUtils.isNotBlank(mainDiagCodeDesc)) {
				medicalRecordDiagnoss = new MedicalRecordDiagnoss();
				medicalRecordDiagnoss.setVisitGuid(visitGuid);
				medicalRecordDiagnoss.setDiagTypeCode(MapUtils.getString(mainDiagRecordMap, "diagTypeCode"));
				medicalRecordDiagnoss.setDiagType(MapUtils.getString(mainDiagRecordMap, "diagTypeName"));
				medicalRecordDiagnoss.setDoctorDiag(mainDiagNameDesc);
				medicalRecordDiagnoss.setDoctorDiagCode(mainDiagCodeDesc);
				medicalRecordDiagnoss.setDiagCode(mainDiagCode);
				medicalRecordDiagnoss.setDiagName(mainDiagName);
				medicalRecordDiagnoss.setInConditionCode(MapUtils.getString(mainDiagRecordMap, "inHospitalDiseaseStateCode"));
				medicalRecordDiagnoss.setInCondition(MapUtils.getString(mainDiagRecordMap, "inHospitalDiseaseStateName"));
				medicalRecordDiagnoss.setTreatmentResultCode(MapUtils.getString(mainDiagRecordMap, "treatResultCode"));
				medicalRecordDiagnoss.setTreatmentResult(MapUtils.getString(mainDiagRecordMap, "treatResultName"));
				list.add(medicalRecordDiagnoss);
			}
		
		}

		// 其他诊断
		List<Map<String, Object>> otherDiseaseDiagRecords = (List<Map<String, Object>>) MapUtils
				.getObject(diseaseDiagInfoMap, "diseaseDiagRecords");

		if (CollectionUtils.isNotEmpty(otherDiseaseDiagRecords)) {
			int otherDiagIndex = 1;
			for (Map<String, Object> otherDiseaseDiagRecord : otherDiseaseDiagRecords) {
				String otherDiagName = MapUtils.getString(otherDiseaseDiagRecord, "diseaseDiagName");
				
				String otherDiagNameDesc = MapUtils.getString(otherDiseaseDiagRecord, "diseaseDiagOriginalDesc");
				
				String otherDiagCode = MapUtils.getString(otherDiseaseDiagRecord, "diseaseDiagCode");
				String otherDiagCodeDesc = MapUtils.getString(otherDiseaseDiagRecord, "diseaseDiagOriginalCode");
				if(StringUtils.isNotBlank(otherDiagCode) || StringUtils.isNotBlank(otherDiagCodeDesc)) {
					medicalRecordDiagnoss = new MedicalRecordDiagnoss();
					medicalRecordDiagnoss.setVisitGuid(visitGuid);
					medicalRecordDiagnoss.setDiagTypeCode(MapUtils.getString(otherDiseaseDiagRecord, "diagTypeCode"));
					medicalRecordDiagnoss.setDiagType(MapUtils.getString(otherDiseaseDiagRecord, "diagTypeName"));
					medicalRecordDiagnoss.setDoctorDiag(otherDiagNameDesc);
					medicalRecordDiagnoss.setDoctorDiagCode(otherDiagCodeDesc);
					medicalRecordDiagnoss.setDiagCode(otherDiagCode);
					medicalRecordDiagnoss.setDiagName(otherDiagName);
					medicalRecordDiagnoss.setInConditionCode(MapUtils.getString(otherDiseaseDiagRecord, "inHospitalDiseaseStateCode"));
					medicalRecordDiagnoss.setInCondition(MapUtils.getString(otherDiseaseDiagRecord, "inHospitalDiseaseStateName"));
					medicalRecordDiagnoss.setTreatmentResultCode(MapUtils.getString(otherDiseaseDiagRecord, "treatResultCode"));
					medicalRecordDiagnoss.setTreatmentResult(MapUtils.getString(otherDiseaseDiagRecord, "treatResultName"));
					medicalRecordDiagnoss.setOrderNo(otherDiagIndex);
					otherDiagIndex++;
					list.add(medicalRecordDiagnoss);
				}

			}

			// 中毒的外部原因
			List<Map<String, Object>> damageAndVenenationDiagRecords = (List<Map<String, Object>>) MapUtils
					.getObject(diseaseDiagInfoMap, "damageAndVenenationDiagRecords");

			if (CollectionUtils.isNotEmpty(damageAndVenenationDiagRecords)) {
				Map<String, Object> damageAndVenenationDiagRecord = damageAndVenenationDiagRecords.get(0);
				String damageAndVenenationDiagName = ObjectUtils
						.getStringValue(damageAndVenenationDiagRecord.get("diseaseDiagName"));
				String damageAndVenenationDiagNameDesc = MapUtils.getString(damageAndVenenationDiagRecord, "diseaseDiagOriginalDesc");
				String damageAndVenenationDiagCode = ObjectUtils
						.getStringValue(damageAndVenenationDiagRecord.get("diseaseDiagCode"));
				
				String damageAndVenenationDiagCodeDesc = MapUtils.getString(damageAndVenenationDiagRecord, "diseaseDiagOriginalCode");

				if(StringUtils.isNotBlank(damageAndVenenationDiagCode) || StringUtils.isNotBlank(damageAndVenenationDiagCodeDesc)) {
					medicalRecordDiagnoss = new MedicalRecordDiagnoss();
					medicalRecordDiagnoss.setVisitGuid(visitGuid);
					medicalRecordDiagnoss.setDiagTypeCode(MapUtils.getString(damageAndVenenationDiagRecord, "diagTypeCode"));
					medicalRecordDiagnoss.setDiagType(MapUtils.getString(damageAndVenenationDiagRecord, "diagTypeName"));
					medicalRecordDiagnoss.setDoctorDiag(damageAndVenenationDiagNameDesc);
					medicalRecordDiagnoss.setDoctorDiagCode(damageAndVenenationDiagCodeDesc);
					medicalRecordDiagnoss.setDiagCode(damageAndVenenationDiagCode);
					medicalRecordDiagnoss.setDiagName(damageAndVenenationDiagName);
					list.add(medicalRecordDiagnoss);
				}
			}

			// 病理诊断
			List<Map<String, Object>> pathologyDiagRecords = (List<Map<String, Object>>) MapUtils
					.getObject(diseaseDiagInfoMap, "pathologyDiagRecords");
			if (CollectionUtils.isNotEmpty(pathologyDiagRecords)) {
				Map<String, Object> pathologyDiagRecord = pathologyDiagRecords.get(0);
				String pathologyDiagName = ObjectUtils.getStringValue(pathologyDiagRecord.get("diseaseDiagName"));
				String pathologyDiagNameDesc = MapUtils.getString(pathologyDiagRecord, "diseaseDiagOriginalDesc");
				String pathologyDiagCode = ObjectUtils.getStringValue(pathologyDiagRecord.get("diseaseDiagCode"));
				String pathologyDiagCodeDesc = MapUtils.getString(pathologyDiagRecord, "diseaseDiagOriginalCode");
				if(StringUtils.isNotBlank(pathologyDiagCode) || StringUtils.isNotBlank(pathologyDiagCodeDesc)) {
					medicalRecordDiagnoss = new MedicalRecordDiagnoss();
					medicalRecordDiagnoss.setVisitGuid(visitGuid);
					medicalRecordDiagnoss.setDiagTypeCode(MapUtils.getString(pathologyDiagRecord, "diagTypeCode"));
					medicalRecordDiagnoss.setDiagType(MapUtils.getString(pathologyDiagRecord, "diagTypeName"));
					medicalRecordDiagnoss.setDoctorDiag(pathologyDiagNameDesc);
					medicalRecordDiagnoss.setDoctorDiagCode(pathologyDiagCodeDesc);
					medicalRecordDiagnoss.setDiagCode(pathologyDiagCode);
					medicalRecordDiagnoss.setDiagName(pathologyDiagName);
					medicalRecordDiagnoss.setPathologyNo(MapUtils.getString(pathologyDiagRecord, "pathologyNumber"));
					list.add(medicalRecordDiagnoss);
				}
			}
		}
		if(CollectionUtils.isNotEmpty(list)) {
			medicalRecordDataManageService.saveOrUpdateMedicalRecordDiagnoss(list,visitGuid);
		}

	}

	

	
	

}
